package com.example.demo.IO;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
/**
* @description: TODO try_with_resource
* @author 杨镇宇
* @date 2022/3/19 21:36
* @version 1.0
*/
public class TestMain {
    public static void main(String[] args) throws IOException {
        String filePath = "F:\\myfile.txt";
        try (
                InputStream fileStream = new FileInputStream(filePath);
                Scanner scanner = new Scanner(fileStream)
        ) {
            int lineno = 0;
            while (scanner.hasNextLine()) {
                lineno += 1;
                String line = scanner.nextLine();
                System.out.printf("%3d >>> %s%n", lineno, line);
            }
            System.out.println("(EOF)");
        } catch (IOException e) {
            System.err.printf("Error occurred when reading '%s'.%n", filePath);
            System.exit(-1);
        }
    }
}
